package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;
import org.akomantoso.core.visitor.AKVisitor;

/**
 * The element quotedStructure is a popup element containing a full structure proposed as an insertion or a replacement.
 * Use attribute for when quotedStructure is used in a mmod or rmod to point to the id of the corresponding refelement.
 * 
 * <pre>
 * 	<xsd:element name="quotedStructure">
 * 		<xsd:complexType>
 * 			<xsd:complexContent>
 * 				<xsd:extension base="popupStructure">
 * 					<xsd:attribute name="for" type="xsd:anyURI" />
 * 				</xsd:extension>
 * 			</xsd:complexContent>
 * 		</xsd:complexType>
 * 	</xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public final class QuotedStructure extends PopupStructure implements ModeTypeItem {

	public static final String ELEMENT = "quotedStructure";
	
	public static final String ATTRIBUTE_FOR = "for";
	
	// Optional
	private String _for;

	public String getFor() {
		return _for;
	}

	public void setFor(String for1) {
		_for = for1;
	}

	
	/**
	 * @see org.akomantoso.core.data.PopupStructure#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeAttribute(out, ATTRIBUTE_FOR, _for);
		super.writeExternal(out);
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.data.PopupStructure#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		_for = in.readAttribute(ATTRIBUTE_FOR);
		super.readExternal(in);
	}

	/**
	 * @see ec.ep.visitor.AKVisitable#accept(ec.ep.visitor.AKVisitor)
	 */
	public void accept(AKVisitor visitor) {
		if (visitor.visitBegin(this)) {
			internalAccept(visitor);
			visitor.visitEnd(this);	
		}
		
	}

}